// 心算能力 线段树
#include <bits/stdc++.h>
using namespace std;
#define lson root << 1
#define rson root << 1 | 1
const int N = 500009;
int n, m;
struct Seg {
  int l, r; // 其实可以省略

  // 不是奇数，就是偶数，其实可以省略写变量，当是为了理解方便。
  int num_ou;
  int sum_ou; // 偶数、奇数的和，
  int num_ji;
  int sum_ji;
  // 懒标记
  int op;  // 0 偶 1 奇
  int val; // 增加的数值
};
Seg tree[4 * N]; // 线段树
void pushup(int root) {
  tree[root].sum_ou = tree[lson].sum_ou + tree[rson].sum_ou;
  tree[root].sum_ji = tree[lson].sum_ji + tree[rson].sum_ji;
  tree[root].num_ou = tree[lson].num_ou + tree[rson].num_ou;
  tree[root].num_ji = tree[lson].num_ji + tree[rson].num_ji;
}

void help(Seg &p, int op, int val) {
  if (op == 0) {
    if (val % 2 == 0) { // 偶数+偶数
      p.sum_ou += p.num_ou * val;
    } else { // 偶数+奇数
      p.sum_ji += p.sum_ou + p.num_ou * val;
      p.sum_ou = 0;

      p.num_ji += p.num_ou;
      p.num_ou = 0;
    }
  } else {
    if (val % 2 == 0) { // 奇数+偶数
      p.sum_ji += p.num_ji * val;

    } else {                                 // 奇数+奇数
      p.sum_ou += p.sum_ji + p.num_ji * val; // 这里调试良久，少了p.sum_ji
      p.sum_ji = 0;

      p.num_ou += p.num_ji;
      p.num_ji = 0;
    }
  }
}

void pushdown(int root, int l, int r) {
  if (tree[root].op == -1)
    return;
  int fop = tree[root].op; // father的标记
  int fval = tree[root].val;
  help(tree[lson], fop, fval);
  help(tree[rson], fop, fval);

  tree[lson].op = fop;
  tree[lson].val = fval;
  tree[rson].op = fop;
  tree[rson].val = fval;

  tree[root].op = -1;
  tree[root].val = 0;
}

void build(int root, int l, int r) {

  if (l == r) {
    tree[root] = {l, r, 1, 0, 0, 0, -1, 0};
    return;
  }
  tree[root].l = l;
  tree[root].r = r;
  int mid = (l + r) / 2;
  build(lson, l, mid);
  build(rson, mid + 1, r);
  pushup(root);
}

void update(int root, int l, int r, int L, int R, int op,
            int v) { // op 表示： 0 偶 1 奇
  if (L <= l && r <= R) {
    help(tree[root], op, v);
    tree[root].op = op;
    tree[root].val = v;
    // 打标记

    return;
  }
  if (L > r || R < l)
    return;

  pushdown(root, l, r);

  int mid = (l + r) / 2;
  update(lson, l, mid, L, R, op, v);
  update(rson, mid + 1, r, L, R, op, v);
  pushup(root);
}

int query(int root, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) {
    return tree[root].sum_ou + tree[root].sum_ji;
  }
  if (ql > r || qr < l)
    return 0;

  pushdown(root, l, r);
  int mid = (l + r) / 2;
  int a = query(lson, l, mid, ql, qr);
  int b = query(rson, mid + 1, r, ql, qr);
  return a + b;
}
void pr() {

  for (int i = 1; i <= n; i++) {
    cout << i << " " << tree[i].l << " " << tree[i].r << endl;
    cout << "偶数个数" << tree[i].num_ou << " 奇数个数" << tree[i].num_ji
         << "偶数的和" << tree[i].sum_ou << "奇数的和 " << tree[i].sum_ji
         << endl;
    cout << endl;
  }
}

int main() {
  ofstream fout =
      ofstream("out.txt"); // 需要较大数据，多次测试，用文件输入输入方便
  ifstream fin = ifstream("in.txt");
  fin >> n >> m;
  build(1, 1, n);

  while (m--) {
    int f;
    fin >> f;
    if (f == 0) {
      int s, t, op, y;
      fin >> s >> t >> op >> y;
      update(1, 1, n, s, t, op, y);
      // pr();
    } else {
      int s, t;
      fin >> s >> t;
      int ans = query(1, 1, n, s, t);
      fout << ans << endl;
    }
  }
  fin.close();
  fout.close();
  return 0;
}
